<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use backend\assets\AppAsset;

/* @var $this yii\web\View */
/* @var $model backend\models\Product */

$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Products', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
//AppAsset::register($this);
//AppAsset::addScript($this,Yii::$app->request->baseUrl."/assets/myjs/myajax.js");
?>
<div class="product-view">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
		<?= Html::a('更新', ['update', 'id' => $model->productId], ['class' => 'btn btn-primary']) ?>
		<?=
		Html::a('删除', ['delete', 'id' => $model->productId], [
			'class' => 'btn btn-danger',
			'data' => [
				'confirm' => '确认删除此项吗?',
				'method' => 'post',
			],
		])
		?>
    </p>
	<?=
	DetailView::widget([
		'template' => '<tr><th{captionOptions}>{label}</th><td{contentOptions}>{value}</td></tr>',
//        'captionOptions'=>'width:100px',
		'model' => $model,
		'attributes' => [
//            'productId',
			['attribute' => 'categoryId',
				'value' => backend\models\Category::getCategoryList_S(2)[$model->categoryId],
			],
			'title',
			'description:ntext',
			'number',
			'price',
//            'cover',
			['attribute' => 'cover',
				'value' => "<img src=//$model->cover style='width: 200px;height: 200px;'>",
				'format' => 'raw',
			],
				['attribute' => 'pictures',
//                'value'     => "<img src=//$model->cover ></img>",
				'value' => \backend\controllers\ProductController::translatePictures($model->productId, $model->pictures),
				'format' => 'raw',
			],
//            'pictures:ntext',
			'issale',
			'ishot',
			'istui',
			'saleprice',
			'ison',
			'createTime',
		],
	])
	?>

</div>
<script type="text/javascript">

	function doDelete(id, key) {
		var r = confirm("你确定要删除吗?");
		if (r == true) {
//            alert("66");
			$.ajax({
				type: "POST",
				url: '<?php echo Yii::$app->request->baseUrl . '/product/remove'; ?>',
				data: {id: id, key: key},
//                processData: false,
//                contentType: false,
//                 dataType:"json",
				success: function (data) {
//                    alert("删除成功");
					console.log(data);
					var div = document.getElementById("" + data);
					div.style.display = 'none';
//                    document.body.scrollTop=100;
				},
				error: function (data) {
					alert("删除失败");
					console.log(data);
				},
//                beforeSend: loading,
//                complete: complete
			})
		}
	}


</script>

